let articles;
// 获取 select 下拉元素
const articleSelect = document.getElementById("articleSelect");

// 获取查重按钮元素
const checkPlagiarismEl = document.getElementById("checkPlagiarism");
// 获取原文
const originalText = document.getElementById("originalText").value;
// 获取显示重复率的元素
const plagiarismRateText = document.getElementById("plagiarismRateText");

// 获取对比文章文本框
const compareText = document.getElementById("compareText");

// TODO：待补充代码
// 请求文章数据并在右侧文本框 id = compareText 中元素默认显示第一篇文章数据
fetch("./data.json")
  .then((rep) => rep.json())
  .then((res) => {
    compareText.innerHTML = res.data.articleOne;
    // TODO：待补充代码
    // id = articleSelect 下拉框改变时显示对应的文章
    articleSelect.addEventListener("change", () => {
      compareText.innerHTML = res.data[articleSelect.value];
    });
  });

// 点击查重按钮显示重复率(已完成)

checkPlagiarismEl.addEventListener("click", function () {
  let plagiarismRate = checkPlagiarism(originalText, compareText.value);
  plagiarismRateText.innerHTML = `重复率：${(plagiarismRate * 100).toFixed(
    2
  )}%`;
});
